<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <!-- 
    父组件会等待子组件挂载完成后才执行mounted操作


   -->
  <div id="app">
    <child v-if="show"></child>
  </div>
  <script src="./vue.js"></script>
  <script>
    Vue.component('child', {
      template: '<div>子组件</div>',
      data () {
        return {
          t: null
        }
      },
      beforeCreate () {
        console.log('子组件创建前')
      },
      created () {
        console.log('子组件创建完成')
        // 给子组件添加一个计时器
        this.t = setInterval(() => {
          console.log(1)
        }, 1000)
      },
      beforeMount () {
        console.log('子组件挂载前')
      },
      mounted () {
        console.log('子组件挂载后')
      },
      beforeUpdate () {
        console.log('子组件更新前')
      },
      updated () {
        console.log('子组件更新后')
      },
      beforeDestroy () {
        console.log('子组件销毁前')
      },
      destroyed () {
        console.log('子组件销毁后')
        clearInterval(this.t)
      }
    })
    const app = new Vue({
      el: "#app",
      data: {
        show: true
      },
      beforeCreate () {
        console.log('创建前')
      },
      created () {
        console.log("创建完成")
      },
      beforeMount () {
        console.log('挂载前')
      },
      mounted () {
        console.log('挂载后')
      },
      beforeUpdate () {
        console.log('更新前')
      },
      updated () {
        console.log('更新后')
      },
      beforeDestroy () {
        console.log('销毁前')
      },
      destroyed () {
        console.log('销毁后')
      }
    })
  </script>
</body>
</html>